/**
  ******************************************************************************
  * Copyright © Beijing WIIP Co., Ltd. 2022-2024. All rights reserved.
  ******************************************************************************
  * @file: ws2812b.h
  * @brief: ws2812b全彩LED功能模块头文件
  *
  ******************************************************************************
  * @note: 调用底层库函数，封装为RBG的功能函数
  *
  *
  ******************************************************************************
  * Change Logs:
  * Date           Author       Notes
  * 2024-05-14     Edward       the first version
  *
  *
  ******************************************************************************
  */

#ifndef __WS2812B_H
#define __WS2812B_H

#include "stdio.h"
#include "tim.h"
//#include "dma.h"

#define WS_LOW          (8)       //0在啊PWM占比     实测为8时，高电平0.35us，低电平0.9us
#define WS_HIGH         (15)      //1在PWM占比        实测为16时，高电平0.63us，低电平0.62us

#define GRB_BITS        (24)      //3*8,3个颜色,每个颜色使用8位数据
#define LED_COUNT_MAX   (36)      //由于硬件驱动能力原因,在软件中限制最大led数量

#define COLOR_VAL_NONE      (WS2812B_pieceRGB(0x00, 0x00, 0x00))  //无色
#define COLOR_VAL_RED       (WS2812B_pieceRGB(0xFF, 0x00, 0x00))  //红色
#define COLOR_VAL_GREEN     (WS2812B_pieceRGB(0x00, 0xFF, 0x00))  //绿色
#define COLOR_VAL_BLUE      (WS2812B_pieceRGB(0x00, 0x00, 0xFF))  //蓝色
#define COLOR_VAL_ORANGE    (WS2812B_pieceRGB(0xFF, 0x80, 0x00))  //橘色
#define COLOR_VAL_WHITE     (WS2812B_pieceRGB(0xFF, 0xFF, 0xFF))  //白色
#define COLOR_VAL_SKY_BLUE  (WS2812B_pieceRGB(0x00, 0xBF, 0xFF))  //深天蓝色

typedef struct
{
    uint8_t b, r, g;
}RGB_Color_t;

typedef union
{
    RGB_Color_t single;
    uint32_t combined;
}RGB_Val_t;


typedef struct
{
    uint8_t pixelLength;
    uint8_t readyLength;
    uint8_t resetLength;
    uint8_t intensity;
    uint16_t DMABuffer[LED_COUNT_MAX][GRB_BITS];
}ws2812b_t;

extern RGB_Val_t RGB_Val;
void WS2812B_init(void);

RGB_Val_t WS2812B_pieceRGB(uint8_t r, uint8_t g, uint8_t b);
void WS2812B_showAllSameColor(ws2812b_t *rgb, RGB_Val_t RGB_Val);
void WS2812B_showOneFlowLight(ws2812b_t *rgb, RGB_Val_t RGB_Val, uint8_t head, uint8_t length);
void WS2812B_showTwoFlowLight(ws2812b_t *rgb, RGB_Val_t RGB_Val1, uint8_t head1, uint8_t length1,
        RGB_Val_t RGB_Val2, uint8_t head2, uint8_t length2);
void WS2812B_showRainbowFlow(ws2812b_t *rgb);

#endif /* __WS2812B_H */
